package com.mingle.iwalk;

import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.location.LocationManager;

public class POIInfo extends TravelerInfo {

	public static 	int 		LOCATION_TYPE_UNKNOWN 	= 0;
	public static 	int 		LOCATION_TYPE_GPS 		= 1;
	public static 	int 		LOCATION_TYPE_NETWORK 	= 2;
	
	public			Bitmap 		picThumb 				= null;
	public 			String 		picPath 				= "";
	public 			int 		locationType 			= LOCATION_TYPE_UNKNOWN;
	public 			Location 	location		 		= null;
	public 			String 		viocePath 				= "";
	public 			int 		relativeTrackId 		= INFO_INVALID_ID;
	
	public POIInfo()
	{
		this.type 					= INFO_TYPE_POI;
	}

	@Override
	public TravelerInfo convert2TravelerInfo(Cursor cursor) {
		super.convert2TravelerInfoBase(cursor);

    	byte[] picThumb = cursor.getBlob(cursor.getColumnIndex(TravelerDB.PICTURE_THUMB));
    	String picPath = cursor.getString(cursor.getColumnIndex(TravelerDB.PICTURE_PATH));
    	int locationType = cursor.getInt(cursor.getColumnIndex(TravelerDB.LOCATION_TYPE));
    	double lat = cursor.getDouble(cursor.getColumnIndex(TravelerDB.LOCATION_LAT));
    	double lon = cursor.getDouble(cursor.getColumnIndex(TravelerDB.LOCATION_LON));
    	double alt = cursor.getDouble(cursor.getColumnIndex(TravelerDB.LOCATION_ALT));
    	double acc = cursor.getDouble(cursor.getColumnIndex(TravelerDB.LOCATION_ACC));
    	String voicePath = cursor.getString(cursor.getColumnIndex(TravelerDB.VOICE_PATH));
    	int trackId = cursor.getInt(cursor.getColumnIndex(TravelerDB.TRACK_ID));
    	
    	/*POIInfo data = new POIInfo();
    	data.id = this.id;
    	data.type = INFO_TYPE_POI;
    	data.title = this.title;
    	data.description = this.description;
    	data.uploadFlag = this.uploadFlag;
    	data.uploadTime = this.uploadTime;
    	data.createTime = this.createTime;
    	data.tagType = this.tagType;
    	data.workingFolderPath = this.workingFolderPath;*/
    	
    	if(picThumb != null)
    	{
    		this.picThumb = BitmapFactory.decodeByteArray(picThumb, 0, picThumb.length);
    		this.picPath = picPath;
    	}
    	this.locationType = locationType;
    	if(locationType != LOCATION_TYPE_UNKNOWN)
    	{
    		this.location = new Location(LocationManager.GPS_PROVIDER);
    		this.location.setLatitude(lat);
    		this.location.setLongitude(lon);
    		this.location.setAltitude(alt);
    		this.location.setAccuracy((float) acc);
    	}
    	
    	this.viocePath = voicePath;
    	this.relativeTrackId = trackId;

		return this;
	}
}
